package com.zm.utils;

import com.alibaba.fastjson.JSON;

import java.util.ArrayList;
import java.util.List;

public class GsonUtils {

    public static String toJson(Object targer){
        return JSON.toJSONString(targer);
    }

    public static <T> T fromJson(String json,Class<T> cls){
        return JSON.parseObject(json,cls);
    }

    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("A");
        list.add("B");
        list.add("C");

        String json = GsonUtils.toJson(list);

        System.out.println(json);

        List<String> strings = (List<String>) GsonUtils.fromJson(json, List.class);
        System.out.println(strings);
    }

}
